﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TransactionServer.General_Classes;
using System.Activities.Presentation.Model;

namespace TransactionServer.ActivityDesign.Components
{
    class EntityControl : ComboBox
    {

        public static readonly DependencyProperty ConnectionProperty =
        DependencyProperty.Register("Connection", typeof(string), typeof(EntityControl),
        new FrameworkPropertyMetadata(
            String.Empty,
            FrameworkPropertyMetadataOptions.AffectsMeasure,
            new PropertyChangedCallback(FilterEntities),
            null
        ));

        public string Connection
        {
            get
            {
                return (string)GetValue(ConnectionProperty);
            }
            set
            {
                SetValue(ConnectionProperty, value);
            }
        }

        public static void FilterEntities(DependencyObject dObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            var entityControl = (EntityControl)dObject;
            if (!String.IsNullOrEmpty(entityControl.Connection))
            {
                entityControl.ItemsSource = StaticContext.context.GetEntities(entityControl.Connection);
            }
        }

        /*
        public EntityControl(ModelItem item, String connectionArgument, String entityArgument)
        {
            var connection = item.Properties[connectionArgument];
            var entity = item.Properties[entityArgument];
        }*/
    }
}
